package hw.pjbk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Quiz1Activity extends Activity implements OnClickListener {
	private Quiz1Application application;
	private Button historyButton;
	private Button mathsButton;
	private TextView summary;
	private static final int EDIT_PREFS = 5;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		application = (Quiz1Application) this.getApplication();

		historyButton = (Button) findViewById(R.id.history_button);
		historyButton.setOnClickListener(this);
		mathsButton = (Button) findViewById(R.id.maths_button);
		mathsButton.setOnClickListener(this);
		summary = (TextView) findViewById(R.id.overall_summary);
		generateSummary();
	}

	@Override
	public void onResume() {
		super.onResume();
		generateSummary();
	}

	private void generateSummary() {
		summary.setText(application.getQuestionsCorrect()
				+ " questions correct " + application.getQuestionsAttempted()
				+ " attempted.");
	}

	@Override
	public void onClick(View arg0) {
		if (arg0 == historyButton) {
			Log.i("QUIZ", "History selected");
			startActivity(new Intent(this, hw.pjbk.MultiChoiceQuestion.class));
		}
		if (arg0 == mathsButton) {
			Log.i("QUIZ", "Maths selected");
			startActivity(new Intent(this, hw.pjbk.NumericQuestion.class));
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.quiz_menu, menu);
		return true;

	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Log.i("MENU", "Preference menu clicked");

		startActivity(new Intent(this, hw.pjbk.QuizPreferences.class));
		return true;
		
		
	}
}
